﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CustomSerializer.Tests
{
    [TestClass]
    public class TestSpeed:TestBase
    {
        object o;
        int objectCount = 0;

        [TestInitialize]
        public void Init()
        {
            InitSerializer();
            objectCount = 0;
            o = prepare(100, 10);
        }

        [TestMethod]
        public void Test4000()
        {
            Trace.WriteLine("ObjectCount=" + objectCount);
            TestObject(ser, o);
            TestObject(serCompressed, o);            
        }

        object prepare(int N, int level)
        {
            if (level == 0) return null;
            Random r = new Random((int)(DateTime.Now.Ticks % int.MaxValue));
            objectCount += N * 4;
            return new object[]
            {
                Enumerable.Range(0, N).Select(p => new SimpleTypes((p%5) != 0)).ToArray(),
                Enumerable.Range(0, N).Select(p => new SimpleTypesNullableArrays((p%5) != 0)).ToList(),
                Enumerable.Range(0, N).Select(p => new {p, item = new ObjectCollections((p%5) != 0)}).ToDictionary(p => p.p, p => p.item),
                Enumerable.Range(0, N).Select(p => new {p, item = new ObjectCollections((p%5) != 0)}).ToDictionary(p => p.p.ToString(), p => p.item),
                prepare(N, level - 1)
            };            
        }
    }
}